﻿@model PagedResultDto<Student>

@{
    ViewData["Title"] = "学生列表页面";
}

<form asp-action="index" method="get">
    <div class="form-actions no-color">
        <input type="hidden" name="CurrentPage" value="@Model.CurrentPage" />
        <input type="hidden" name="Sorting" value="@Model.Sorting" />
        <p>
            请输入名称：
            <input type="text" name="FilterText" value="@Model.FilterText" />
            <input type="submit" value="查询" class="btn btn-outline-dark" />
            | <a asp-action="index">返回所有列表</a>
            | <a asp-action="create">添加学生</a>
        </p>
    </div>
</form>

<div class="row">
    <div class="table-responsive-sm">
        @if (Model.Data.Any())
        {

            <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th scope="col">头像</th>
                        <th scope="col" class="sort-link">
                            <a asp-action="index" asp-route-Sorting="Name"
                               asp-route-CurrentPage="@Model.CurrentPage"
                               asp-route-FilterText="@Model.FilterText">名字</a>
                            <a class="pl-3" asp-action="index"
                               asp-route-CurrentPage="@Model.CurrentPage"
                               asp-route-FilterText="@Model.FilterText"
                               asp-route-Sorting="Name desc">降序</a>
                        </th>
                        <th scope="col">
                            <a asp-action="index" asp-route-Sorting="Email"
                               asp-route-CurrentPage="@Model.CurrentPage"
                               asp-route-FilterText="@Model.FilterText">邮箱地址</a>
                            <a class="pl-3" asp-action="index"
                               asp-route-CurrentPage="@Model.CurrentPage"
                               asp-route-FilterText="@Model.FilterText"
                               asp-route-Sorting="Email desc">降序</a>
                        </th>
                        <th scope="col">
                            <a class="pl-3" asp-action="index" asp-route-Sorting="Marjor "
                               asp-route-CurrentPage="@Model.CurrentPage"
                               asp-route-FilterText="@Model.FilterText">主修科目</a>
                            <a class="pl-3" asp-action="index"
                               asp-route-CurrentPage="@Model.CurrentPage"
                               asp-route-FilterText="@Model.FilterText"
                               asp-route-Sorting="Marjor desc">降序</a>
                        </th>
                        <th scope="col">
                            <a class="pl-3" asp-action="index" asp-route-Sorting="EnrollmentDate"
                               asp-route-CurrentPage="@Model.CurrentPage"
                               asp-route-FilterText="@Model.FilterText">入学时间</a>
                            <a class="pl-3" asp-action="index"
                               asp-route-CurrentPage="@Model.CurrentPage"
                               asp-route-FilterText="@Model.FilterText"
                               asp-route-Sorting="EnrollmentDate desc">降序</a>
                        </th>
                        <th scope="col">操作</th>
                    </tr>
                </thead>

                <tbody>

                        @foreach (var student in Model.Data)
                        {
                            var photoPath = "~/img/avatar/noimage.png";
                            if (student.PhonePath != null)
                            {
                                photoPath = "~/img/avatar/" + student.PhonePath;
                            }

                            <tr>
                                <td>
                                    <img class="table-img img-thumbnail" src="@photoPath" asp-append-version="true" />
                                </td>

                                <th scope="row">@student.Name</th>
                                <td>@student.Email</td>
                                <td>@student.Marjor.GetDisplayName()</td>
                                <td>@student.EnrollmentDate</td>
                                <td>
                                    <form method="post" asp-controller="home" asp-action="delete" asp-route-id="@student.Id">
                                        <a asp-controller="home" class="btn btn-info" asp-action="Detail"
                                           asp-route-id="@student.Id">查看</a>
                                        <a asp-controller="home" class="btn btn-primary m-1" asp-action="edit"
                                           asp-route-id="@student.Id">编辑</a>
                                        <span id="confirmDeleteSpan_@student.Id" style="display:none">
                                            <span>您确定要删除？</span>
                                            <button type="submit" class="btn btn-danger">是</button>
                                            <a href="#" class="btn btn-primary" onclick="confirmDelete('@student.Id', false)">否</a>
                                        </span>
                                        <span id="deleteSpan_@student.Id">
                                            <a href="#" class="btn btn-danger" onclick="confirmDelete('@student.Id', true)">删除</a>
                                        </span>
                                    </form>
                                </td>
                            </tr>
                        }
                    </tbody>
            </table>
        }
    </div>

    @*分页*@
    <div>
        <ul class="pagination">
            <li class="page-item @(!Model.ShowFirst ? "disabled" : "")">
                <a asp-route-CurrentPage="1"
                   asp-route-FilterText="@Model.FilterText"
                   asp-route-Sorting="@Model.Sorting"
                   class="page-link">
                    首页
                </a>
            </li>

            <li class="page-item @(!Model.ShowPrevious ? "disabled" : "")">
                <a asp-route-CurrentPage="@(Model.CurrentPage - 1)"
                   asp-route-FilterText="@Model.FilterText"
                   asp-route-Sorting="@Model.Sorting"
                   class="page-link">
                    前一页
                </a>
            </li>

            @for (var i = 1; i <= Model.TotalPages; i++)
            {
                <li class="page-item @(i == Model.CurrentPage?"disabled" : "")">
                    <a asp-route-currentpage="@i" ></a>
                    <a asp-route-CurrentPage="@(Model.CurrentPage + 1)"
                       asp-route-FilterText="@Model.FilterText"
                       asp-route-Sorting="@Model.Sorting"
                       class="page-link">
                        @i
                    </a>
                </li>
            }

            <li class="page-item @(!Model.ShowNext ? "disabled" : "")">
                <a asp-route-CurrentPage="@(Model.CurrentPage + 1)"
                    asp-route-FilterText="@Model.FilterText"
                    asp-route-Sorting="@Model.Sorting"
                   class="page-link">
                    后一页
                </a>
            </li>

            <li class="page-item @(!Model.ShowLast ? "disabled" : "")">
                <a asp-route-CurrentPage="@(Model.TotalPages)"
                    asp-route-FilterText="@Model.FilterText"
                    asp-route-Sorting="@Model.Sorting"
                   class="page-link">
                    最后一页
                </a>
            </li>
        </ul>
    </div>
</div>

@section Scripts
{
    <script src="~/js/CustomScript.js" asp-append-version="true"></script>
}